import React from 'react';
import './jquery-ui-1.10.2.custom.min'
import './fullcalendar.min'
import './fullcalendar.less'
import './index.less'

class Course extends React.Component {
    constructor(props) {
        super(props);
    }
    render(){
        return(
            <div id="calendar" className="calendar"></div>
        )
    }
    componentDidMount(){

        var course = this.props.course
        $(function () {
            var events = []
            course.map(function (node, idx) {
                for (var i in node) {
                    node[i].map(function (node_1, idx_1) {
                        var myDate=new Date("2017/8/27");
                        var d = myDate.getDate();
                        var m = myDate.getMonth();
                        var y = myDate.getFullYear();
                        d= d + (node_1.dayOfWeek-0)+(idx-1)*7
                        var bh = node_1.time[0]
                        if(bh>4){
                            bh=bh-0+8
                            var eh = node_1.time.slice(-1)-0+9
                            events.push({
                                start: new Date(y, m, d,bh,30),
                                end: new Date(y, m, d,eh,30),
                                title: node_1.name+' '+node_1.classRoom,
                                allDay: false
                            })
                        }else {
                            bh = bh - 0 + 7
                            var eh = node_1.time.slice(-1) - 0 + 8

                            events.push({
                                start: new Date(y, m, d, bh, 0),
                                end: new Date(y, m, d, eh, 0),
                                title: node_1.name + node_1.classRoom,
                                allDay: false
                            })
                        }
                    })
                }
            })
            $('#calendar').fullCalendar({
                header: {
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                },
                firstDay: 1,
                editable: true,
                timeFormat: 'H:mm',
                axisFormat: 'H:mm',
                events: events
            });

        });

    }
}

export default Course